#!/usr/bin/perl -w

####################################################
# Copyright (c) 2002-2007 BioWare Corp.
# http://www.bigdaddymonitor.org
#
# This file is part of the BigDaddy Monitoring
# program. It is free software distributed under
# the terms of the BSD License. It is ditributed
# in the hopes that it will be useful, but
# WITHOUT ANY WARRANTY; without event the implied
# warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE.
#
# The BSD License is available from:
# http://www.opensource.org/licenses/bsd-license.php
####################################################

# Author Dups <dups@dups.ca>
# 26.08.2007
#
# This script takes input and creates a sample ini file.

use strict;

my $bigdaddy_ini = "sample.bigdaddy.ini";

my $smtpserver = "localhost";
my $fromemail = "root\@localhost";
my $non_critical_restart_email = 'root@localhost';
my $critical_restart_email = 'root@localhost';
my $api_url = "http://bigdaddy/api/";

print "This script will create a sample bigdaddy.ini file. Please note that there are many more options
relating to creating a MASTER/MASTER or MASTER/SLAVE setup. This will only ask you questions for setting
up a SINGLE instance of BigDaddy, please refer to the documentation both in the bigdaddy.ini file that is
created AND in the manual to help you configure BigDaddy to get the most out of it \n\n

[Press any key to continue]

";

my $wait_for_key = <>;


#Ask for input
print "What is the SMTP Server that you wish to use for BigDaddy Emails
[default = localhost] > ";
chomp ( my $smtpserver_input = <> );

if ($smtpserver_input ne '')
{
    $smtpserver = $smtpserver_input;
}

print "What email address would you like to appear in the from line of emails?
[default = root\@localhost] > ";

chomp (my $fromemail_input = <> );

if ($fromemail_input ne '')
{
    $fromemail = $fromemail_input;
}

print "What email address would you like to notify when the application restarts (non-critical)
[default = root\@localhost] > ";

chomp (my $non_critical_restart_email_input = <> );

if ($non_critical_restart_email_input ne '')
{
    $non_critical_restart_email = $non_critical_restart_email_input;
}

print "What email address would you like to notify when the application cannot be automaticall restarted?
[default = root\@localhost] > ";

chomp (my $critical_restart_email_input = <> );

if ($critical_restart_email_input ne '')
{
    $critical_restart_email = $critical_restart_email_input;
}


print "What is the url that you want to use for the Web API
[default = http://bigdaddy/api/] > ";

chomp (my $api_url_input = <> );

if ($api_url_input ne '')
{
    $api_url = $api_url_input;
}

my $ini_text = << "END"

#Auto-created sample bigdaddy.ini file for BigDaddy Version 4
#Released under the ... License
#Please see... for more details

[main]
#   what smtp server to use, if you use a server outside of bigdaddy remember that this server
#   may go down... it should normally be localhost
smtpserver = $smtpserver

#   define the email address emails should appear to come from
fromemail = $fromemail

#   define the dbhandle to use from the dbconfig.ini
dbinihandle = bigdaddy

#   each bd instance/server needs to have a different processname
thisprocessname = bd1

#   define the dbhandle to use for storing statistical/historical data
#   this data is not critical to bigdaddy but can be quite enormous in how much data space is required
historydbhandle = bigdaddystats

#   define how bigdaddy is operating
#    if set to "single", then it is the only instance of bigdaddy running
#    if set to "masterslave", then it is running as two instances one is a master and the other a slave
#    if set to "multimaster", then two (or more) instances of bigdaddy are running against
#       one multi-master database and one will always be operating
bdprocessing = single

#   emailstring to send to when bigdaddy has been restarted by bigdaddy check
#   noncritical email (seperate emails with commas)
noncriticalrestart = $non_critical_restart_email

#   emailstring to send to when bigdaddy cannot be restarted by bigdaddy check
#   critical email (seperate emails with commas)
criticalrestart = $critical_restart_email

#   directory to dump history mysqldumps to
historydumpdir = /bigdaddy/history/

#   is this server the cron master for the Bigdaddy crons which should only be running on one server?
#   valid values are true and false
cronmaster = true

#   This is the URL that will be used for the web api to control Crons and get informaation
url = $api_url

#   Processing directives for masterslave configuration
[masterslave]

#   this can be either master or slave
thisinstance = master

#   location of the master instance
masterinstance = bigdaddy.master

#   location of the slave instance
slaveinstance = bigdaddy.slave

#   dbhandle in dbconfig.ini to use for master
#   this will override the main dbinihandle value for the master instance
masterdbhandle = bigdaddy

#   dbhandle in dbconfig.ini to use for slave
#   this will override the main dbinihandle value for the slave instance
slavedbhandle = bigdaddy

#   threshold before slave takes over from master in seconds
threshold = 300

#   processing directives for multimaster configuration
[multimaster]

#   threshold to pickup from another instance/server
threshold = 300
END
;

print "\n\nWriting sample ini file to $bigdaddy_ini, rename file to bigdaddy.ini"; 

open (BIGDADDY_INI, "> $bigdaddy_ini");
print BIGDADDY_INI $ini_text;
close (BIGDADDY_INI);

print "\n\nDone!";




